// pages/service/watch/watch.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sum: '',
    money: 0,
    list: [],
    show: false,
    mingxi:[],
    name:"",
    phone:'',
  },
  withdraw() {
    this.setData({ show: true });
  },
  getUserInfo(event) {
    var that = this;
    if (that.data.sum == 0) {
      wx.showToast({
        title: '请输入提现金额',
        icon: 'none',    //如果要纯文本，不要icon，将值设为'none'
        duration: 2000
      })
    } else {
      if (Number(that.data.sum) !== null && Number(that.data.sum) <= that.data.list.moneys && that.data.phone != '' && that.data.name!=''){
        //startwork
        var local = wx.getStorageSync('local')
        var ordercode = that.formatDate(20);
      var name =that.data.name;
        var phone = that.data.phone;
        var data = {
          'phone':phone,
          'name': name,
          'paySigns': ordercode,
          "sum": (that.data.money + that.data.money*0.007).toFixed(2),
          "local": local,
          'openid': wx.getStorageSync('openid'),
        }
        app.api.getData('admin/wall', data, (res) => {
          console.log(res)
          if (res.data == "ok") {
            var local = wx.getStorageSync('local')
            local = {
              "local": local
            }
            app.api.getData('admin/getwall', local, (res) => {
              that.setData({
                list: res.data[0],
                mingxi: res.data[0].list.reverse()
              })
            })
            wx.showToast({
              title: '提现成功',
              icon: '',    //如果要纯文本，不要icon，将值设为'none'
              duration: 2000
            })
          } else{
            wx.showToast({
              title: res.data,
              icon: 'none',    //如果要纯文本，不要icon，将值设为'none'
              duration: 2000
            })
          }
        })
      } else {
        wx.showToast({
          title: '信息有误，请重新输入',
          icon: 'none',    //如果要纯文本，不要icon，将值设为'none'
          duration: 2000
        })
      }
    }
  },
  formatDate(len) {
    len = len || 42;
    var chars = '1234567890';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = chars.length;
    var pwd = '';
    for (var i = 0; i < len; i++) {
      pwd += chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;

  },

  onClose() {
    this.setData({ close: false });
  },
  onChange(e) {
    var much = Number(Number(e.detail).toFixed(2));
    console.log(much)
    this.setData({
      sum: e.detail,
      money: much,
    })
  },
  onChange1(e) {
    this.setData({
      name: e.detail
    })
  },
  onChange2(e) {
    this.setData({
      phone: e.detail
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var local = wx.getStorageSync('local')
    console.log(local)
    local = {
      "local": local
    }
    app.api.getData('admin/getwall', local, (res) => {
      that.setData({
        list: res.data[0],
        mingxi: res.data[0].list.reverse(),
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})